<?php
/**
 * 
 *
 * @category 
 * @package 
 * @author chenping<chenping@shopex.cn>
 * @version $Id: Z
 */
class erpapi_shop_matrix_vop_response_order extends erpapi_shop_response_order
{
    protected $_update_accept_dead_order = true;

    protected function get_update_components()
    {
        $components = array('markmemo','custommemo','marktype');

        if ( ($this->_ordersdf['pay_status'] != $this->_tgOrder['pay_status']) || ($this->_ordersdf['shipping']['is_cod']=='true' && $this->_ordersdf['status'] == 'dead') ) {
            $refundApply = app::get('ome')->model('refund_apply')->getList('apply_id',array('order_id'=>$this->_tgOrder['order_id'],'status|noequal'=>'3'));
            // 如果没有退款申请单，以前端为主
            if (!$refundApply) {
                $components[] = 'master';
            }
        }

        return $components;
    }

    protected function _analysis()
    {
        if ($this->_ordersdf['status'] == 'dead' && $this->_ordersdf['shipping']['is_cod'] != 'true') $this->_ordersdf['pay_status'] = '5';

        parent::_analysis();
    }
   protected function _operationSel()
    {
        parent::_operationSel();

        ///////////////////////////////////////////
        // 解决订单备注没更新(平台问题，备注修改订单最后时间不变),
        // 同时防止比较明细，失败订单恢复后又重新更新为失败订单
        ///////////////////////////////////////////
        $update = false;

        if ($this->_tgOrder) {
            $last_custom_mark = array();$last_mark_text=array();
            $custom_mark = array();
            if ($this->_tgOrder['custom_mark'] && is_string($this->_tgOrder['custom_mark'])) {
                $custom_mark = unserialize($this->_tgOrder['custom_mark']);
            }

            $mark_text = array();
            if ($this->_tgOrder['mark_text'] && is_string($this->_tgOrder['mark_text'])) {
                $mark_text = unserialize($this->_tgOrder['mark_text']);
            }

            foreach ((array) $custom_mark as $key => $value) {
                if ( strstr($value['op_time'], "-") ) $value['op_time'] = strtotime($value['op_time']);

                if ( intval($value['op_time']) > intval($last_custom_mark['op_time']) ) {
                    $last_custom_mark = $value;
                }
            }

            foreach ((array) $mark_text as $key => $value) {
                if ( strstr($value['op_time'], "-") ) $value['op_time'] = strtotime($value['op_time']);

                if ( intval($value['op_time']) > intval($last_mark_text['op_time']) ) {
                    $last_mark_text = $value;
                }
            }

            if ( ($this->_ordersdf['custom_mark'] && $this->_ordersdf['custom_mark'] != $last_custom_mark['op_content']) ||
                ($this->_ordersdf['mark_text'] && $this->_ordersdf['mark_text'] != $last_mark_text['op_content'] ) ) {
                $update = true;
            }
        }

        // 即不是更新，也是不是创建,才做这样逻辑判断
        if (!$this->_operationSel && $update) {
            $this->_operationSel = 'update';
        }
    }
}
